<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
  <title>VForm Designer Demo</title>
  <link rel="stylesheet" href="cdn.staticfile.org/element-ui/2.15.7/theme-chalk/index.min.css">
  <link rel="stylesheet" href="VFormBuilds/dist/VFormDesigner.css?t=20210730"> <!-- 根据Web服务器或CDN路径修改 -->
</head>
<body>

<div id="app">
  <v-form-designer ref="vfDesignerRef" :designer-config="designerConfig">
    <template #customToolButtons>
      <el-button type="text" @click="saveFormJson">保存</el-button>
      <el-button type="text" @click="closeFormDesign">关闭</el-button>
    </template>
  </v-form-designer>
</div>

<script type="text/javascript">
  if (!!window.ActiveXObject || "ActiveXObject" in window) { //IE load polyfill.js for Promise
    var scriptEle = document.createElement("script");
    scriptEle.type = "text/javascript";
    scriptEle.src = "https://cdn.bootcss.com/babel-polyfill/6.23.0/polyfill.min.js"
    document.body.appendChild(scriptEle)
  }
</script>
<script src="lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.min.js"></script>
<script src="cdn.staticfile.org/element-ui/2.15.7/index.min.js"></script>
<script src="cdn.jsdelivr.net/npm/js-base64@3.7.5/base64.min.js"></script>
<script src="VFormBuilds/dist/VFormDesigner.umd.min.js?t=20210730"></script> <!-- 根据Web服务器或CDN路径修改 -->
<script src="libs/jquery.min.js"></script>
<script src="plugins/layer/layer.js"></script>
<script src="js/common.js"></script>
<script>
  new Vue({
    el: '#app',
    data: {
      designerConfig: {
        resetFormJson: false,
        toolbarMaxWidth: 400,
        exportCodeButton: false,  //是否显示导出代码按钮
        generateSFCButton: false,  //是否显示生成SFC按钮
      },
      templateId: '',
      formJson: '{"widgetList":[],"formConfig":{"modelName":"formData","refName":"vForm","rulesName":"rules","labelWidth":80,"labelPosition":"left","size":"","labelAlign":"label-left-align","cssCode":"","customClass":"","functions":"","layoutType":"PC","onFormCreated":"","onFormMounted":"","onFormDataChange":""}}',
    },
    created() {
      this.initEformOptions();
    },
    methods: {
      initEformOptions: function() {
        this.templateId = T.p('templateId');
        var that = this;
        $.ajax({
          url: T.webRoot + '/eform/eformtemplate/info/' + that.templateId,
          type: 'GET',
          success: function(res) {
            that.formJson = res.data.templateConfig;
            that.$refs.vfDesignerRef.setFormJson(that.formJson);
          },
          error: function(err) {
            console.log('err', err)
          }
        });
      },
      saveFormJson: function () {
        this.formJson = this.$refs.vfDesignerRef.getFormJson();
        let designForm = {
          "templateId": this.templateId,
          "templateConfig": Base64.encode(JSON.stringify(this.formJson))
        };
        $.ajax({
          url: T.webRoot + '/eform/eformtemplate/update',
          type: 'POST',
          data: JSON.stringify(designForm),
          success: function(res) {
            console.log('saveFormJson', res)
          },
          error: function(err) {
            console.log('saveFormJson->err', err)
          }
        });
      },
      closeFormDesign: function () {
        location.href = T.webRoot + '/#templates.html'
      }
    }
  });
</script>
</body>
</html>